



import { Service } from 'egg';
import axios from 'axios';

/**
 * Test Service
 */
export default class HighQuality extends Service {

  
    public async getBanner() {

        const baseUrl = this.config.baseUrl;
        const result = await axios({
            url:`${baseUrl}/discover`,
            method:'get',
            headers:{

                Referer: "http://music.163.com",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3380.0 Safari/537.36"
            }
        });
        const data = result.data.toString();
        const pattern = /<script[^>]*>\s*window\.Gbanners\s*=\s*([^;]+?);\s*<\/script>/g;

        const exec = pattern.exec(data);
        let banner = '{}'

        if(exec ){
            banner = exec[1]
        }
        return banner
    }

}


